# -*- encoding:utf8 -*-

"""
测试使用。
用于调整系统时间
"""
import datetime as datetime_orig
import sys

class DatetimeStub(object):
    """A datetimestub object to replace methods and classes from 
    the datetime module. 

    Usage:
        import sys
        sys.modules['datetime'] = DatetimeStub()
    """
    class datetime(datetime_orig.datetime):
        @classmethod
        def set_now(cls,now):
            cls.data_now=now

        @classmethod
        def now(cls):
            """Override the datetime.now() method to return a
            datetime one year in the future
            """
            if getattr(cls,'data_now',None):
                return cls.data_now
            else:
                return datetime_orig.datetime.now()
            #result = datetime_orig.datetime.now()
            #return result.replace(year=result.year + 1)
        @classmethod
        def localtime(cls,time):
            return time

    def __getattr__(self, attr):
        """Get the default implementation for the classes and methods
        from datetime that are not replaced
        """
        return getattr(datetime_orig, attr)


sys.modules['datetime']=DatetimeStub()
import datetime